<template>
  <div class="cart-control">
    <transition name="fade">
      <div 
        class="control-btn decrease" 
        v-if="food.count > 0" 
        @click.stop="decreaseCart"
        :class="{ 'disabled': disabled }"
      >
        <el-icon><Remove /></el-icon>
      </div>
    </transition>
    <span class="count" v-if="food.count > 0">{{ food.count }}</span>
    <div 
      class="control-btn increase" 
      @click.stop="increaseCart"
      :class="{ 'disabled': disabled }"
    >
      <el-icon><CirclePlus /></el-icon>
    </div>
  </div>
</template>

<script setup>
import { Remove, CirclePlus } from '@element-plus/icons-vue';

const props = defineProps({
  food: {
    type: Object,
    required: true
  },
  disabled: {
    type: Boolean,
    default: false
  }
});

const emit = defineEmits(['add', 'remove']);

const increaseCart = () => {
  if (!props.disabled) {
    emit('add', props.food);
  }
};

const decreaseCart = () => {
  if (!props.disabled) {
    emit('remove', props.food);
  }
};
</script>

<style scoped>
.cart-control {
  display: flex;
  align-items: center;
  gap: 5px;
}

.control-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background-color: #ff5339;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
}

.control-btn:hover {
  background-color: #ff3a1c;
}

.control-btn.disabled {
  background-color: #ccc;
  cursor: not-allowed;
}

.control-btn .el-icon {
  font-size: 16px;
  font-weight: bold;
}

.count {
  font-size: 14px;
  color: #333;
  min-width: 16px;
  text-align: center;
}

.fade-enter-active, .fade-leave-active {
  transition: all 0.3s;
}

.fade-enter-from, .fade-leave-to {
  opacity: 0;
  transform: translateX(15px) rotate(180deg);
}
</style>